package com.sso.oauth.controller;

import com.microsoft.aad.adal4j.AuthenticationResult;
import com.sso.oauth.constants.AuthParameterNames;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Derry Luo on 2019/5/10.
 */
@RequestMapping("/storefront/token")
@RestController
public class TokenController {

    @RequestMapping("getAccessToken")
    public String getAccessToken(HttpServletRequest request) {

        AuthenticationResult authenticationResult = (AuthenticationResult) request.getSession().getAttribute(AuthParameterNames.PRINCIPAL_SESSION_NAME);
        if (authenticationResult == null) {
//            return "AccessToken :123525252";
            return null;
        }
        return authenticationResult.getAccessToken();
    }

}
